/**
 * @param {Array<string>} openTimeArray
 * Array length: 7 from Sunday to Saturday
 * 00: 不开放 01:上午开放 10: 下午开放 11: 全天开放
 */
export function a2s(openTimeArray) {
  if (openTimeArray.length !== 7) {
    throw new RangeError('开放时间数组长度必须为7')
  }
  let str = openTimeArray[0]
  for (let i = 1; i < 7; i++) {
    str += openTimeArray[i]
  }
  return str
}

/**
 * @param {string} openTimeString openTimeString.length=14
 */
export function s2a(openTimeString) {
  if (openTimeString.length !== 14) {
    throw new RangeError('开放时间字符串长度必须为14')
  }
  const arr = []
  for (let i = 0; i < 14; i++) {
    arr.push(openTimeString.substr(i++, 2))
  }
  return arr
}

/**
 * @param {string} openTimeString openTimeString.length=14
 */
export function s2as(openTimeString) {
  while (openTimeString.length < 14) {
    openTimeString += '0'
  }
  if (openTimeString.length !== 14) {
    throw new RangeError('开放时间字符串长度必须为14')
  }
  const arr = []
  for (let i = 0; i < 14; i++) {
    arr.push(code2string(openTimeString.substr(i++, 2)))
  }
  return arr
}

export function code2string(code) {
  switch (`${code}`) {
    case '00':
      return '不开放'
    case '01':
      return '上午开放'
    case '10':
      return '下午开放'
    case '11':
      return '全天开放'
  }
}

export function string2code(str) {
  switch (str) {
    case '不开放':
      return '00'
    case '上午开放':
      return '01'
    case '下午开放':
      return '10'
    case '全天开放':
      return '11'
  }
}

// console.log(s2a('11111111111100'))
